package com.yuju.account.dao.impl;


import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.yuju.model.account.AccountModel;
import com.yuju.account.dao.IAccountDao;
import com.yuju.account.dao.entity.Account;
import com.yuju.account.dao.mapper.AccountMapper;
import com.yuju.account.model.RoomOrderModel;
import com.yuju.common.PageModel;
import com.yuju.common.core.dao.AbstractBaseDao;
import com.yuju.persist.base.mapper.BaseMapper;

/**
 * 类名：AccountDaoImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年11月27日 上午9:45:03  <br />
 * @version : 1.1 <br />
 */
@Repository
public class AccountDaoImpl extends AbstractBaseDao<AccountModel, Account, String> implements IAccountDao {
	
	@Autowired
	private AccountMapper accountMapper;
	
	@Override
	public BaseMapper<Account, String> getMapper() {
		// TODO Auto-generated method stub
		return accountMapper;
	}

	@Override
	public int updateBalanceByOrderId(Map<String, Object> map) {
		return accountMapper.updateBalanceByOrderId(map);
	}

	@Override
	public int updateBalanceByRoomGuestId(Map<String, Object> map) {
		return accountMapper.updateBalanceByRoomGuestId(map);
	}

	@Override
	public int updateBalanceByReserveId(Map<String, Object> map) {
		return accountMapper.updateBalanceByReserveId(map);
	}

	@Override
	public List<AccountModel> listByOrderIds(List<String> list) {
		return convertP2M(accountMapper.listByOrderIds(list));
	}

	@Override
	public PageModel listOrderAccount(AccountModel accountModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> beanMap = getBeanMap(accountModel, currentPage, rows);
		Integer total = countByMap(beanMap);
		if ( total == 0) {
			pageModel.setTotal(total);
			return pageModel;
		}else if(total == null){
			return null;
		}
		pageModel.setTotal(total);
		List<Account> list = accountMapper.listOrderAccount(beanMap);
		List<AccountModel> modelList = convertP2M(list);
		pageModel.setRows(modelList);
		return pageModel;
	}

	@Override
	public Integer countByMap(Map<Object, Object> map) {
		return accountMapper.countByMap(map);
	}

	@Override
	public RoomOrderModel getRoomOrder(String id) {
		return accountMapper.getRoomOrder(id);
	}

	@Override
	public List<AccountModel> listOrderAccountNoPage(AccountModel accountModel) {
		return convertP2M(accountMapper.listOrderAccount(getBeanMap(accountModel)));
	}

	@Override
	public int getAccountAmountSum(AccountModel accountModel) {
		return accountMapper.getAccountAmountSum(getBeanMap(accountModel));
	}

	@Override
	public List<AccountModel> getCTReport(AccountModel accountModel) {
		return accountMapper.getCTReport(getBeanMap(accountModel));
	}
	

	@Override
	public int countCT(Map<Object, Object> map) {
		return accountMapper.countCT(map);
	}

	@Override
	public PageModel getCTReportPage(AccountModel accountModel, Integer currentPage, Integer rows) {
		PageModel pageModel = new PageModel(currentPage, rows);
		Map<Object, Object> beanMap = getBeanMap(accountModel, currentPage, rows);
		Integer total = countCT(beanMap);
		if ( total == 0) {
			return null;
		}
		pageModel.setTotal(total);
		List<AccountModel> list = accountMapper.getCTReport(beanMap);
		pageModel.setRows(list);
		return pageModel;
	}

	@Override
	public BigDecimal getCTMoneySum(AccountModel accountModel) {
		return accountMapper.getCTMoneySum(getBeanMap(accountModel));
	}


}
